package com.xbongbong.saas.domain.entity;

import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.Entity;
import com.xbongbong.saas.enums.CallLogResultEnum;
import com.xbongbong.saas.enums.CallLogTypeEnum;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author youli.chen
 * @version v1.0
 * @description: 通话记录实体类
 * @date 2019/2/18 20:54
 * @since v1.0
 */
@Setter
@Getter
@ToString
public class CallCenterCallLogEntity extends Entity {

    public CallCenterCallLogEntity() {
        del = 0;
    }

    public CallCenterCallLogEntity(String corpid, String userId, Integer moduleType, Long refId, Integer refType,
                                   String refName, Integer callTime, String anotherPhoneNum) {
        this();
        this.corpid = corpid;
        this.userId = userId;
        this.moduleType = moduleType;
        this.refId = refId;
        this.refType = refType;
        this.refName = refName;
        this.callTime = callTime;
        this.callTimeShow = DateUtil.getString(callTime, DateUtil.SDF);
        this.anotherPhoneNum = anotherPhoneNum;
        this.type = CallLogTypeEnum.INBOUND.getCode();
        this.result = CallLogResultEnum.FAIL.getCode();
    }

    public CallCenterCallLogEntity(String corpid, Long refId, Integer refType, String refName, Integer moduleType,
                                   Integer callTime, Integer duration, String agentPhoneNum, String anotherPhoneNum, Integer type, Integer result) {
        this();
        this.corpid = corpid;
        this.refId = refId;
        this.refType = refType;
        this.refName = refName;
        this.moduleType = moduleType;
        this.callTime = callTime;
        this.duration = duration;
        this.agentPhoneNum = agentPhoneNum;
        this.anotherPhoneNum = anotherPhoneNum;
        this.type = type;
        this.result = result;
    }

    /**
     * 主键
     */
    private Long id;
    /**
     * 公司ID
     */
    private String corpid;
    /**
     * 员工userId
     */
    private String userId;
    /**
     * 对象id
     */
    private Long refId;
    /**
     * 对象类型，参考XbbRefTypeEnum
     */
    private Integer refType;
    /**
     * 对象名称
     */
    private String refName;
    /**
     * 微应用信息，参考AppStoreTypeEnum
     */
    private Integer moduleType;
    /**
     * 呼叫时间的时间戳，秒为单位
     */
    private Integer callTime;
    /**
     * 通话时长，秒为单位
     */
    private Integer duration;
    /**
     * 响铃时长，秒为单位
     */
    private Integer ringTime;
    /**
     * 坐席号码
     */
    private String agentPhoneNum;
    /**
     * 另一方号码
     */
    private String anotherPhoneNum;

    /**
     * 隐藏掉的另一方号码
     */
    private String hiddenPhoneNum;

    /**
     * 通话类型，0: 呼入（度言：INBOUND）；1：呼出（度言：OUTBOUND）
     */
    private Integer type;
    /**
     * 通话结果，1: 成功；0：失败（度言字段 outcome 呼叫结果，SUCCESS: 成功；FAIL：失败）；2：需要同步
     */
    private Integer result;
    /**
     * 是否已经与话务中心平台进行过同步
     */
    private Boolean isSynced;
    /**
     * 电话类别
     */
    private String code;
    /**
     * 电话备注
     */
    private String note;
    /**
     * 用于请求录音
     */
    private String callUuid;
    /**
     * 录音文件地址
     */
    private String recordUrl;
    /**
     * 执行语音转写的平台，讯飞：xunfei，阿里云：aliyun
     */
    private String translatePlatform;
    /**
     * 录音转文字的文本，只有对话内容的文本
     */
    private String recordContent;
    /**
     * 录音转文字的解析结果
     */
    private String translateData;

    /**
     * 通话ID
     */
    private String callId;

    /**
     * 呼叫中心实例ID
     */
    private String instanceId;

    /**
     * 挂断人：0-客户，1-员工
     */
    private Integer hangUp;

    /**
     * 是否接听：0-未接通，1-已接听
     */
    private Integer answer;

    /**
     * 通话流程JSON
     */
    private String callProcess;

    /**
     * 技能组ID
     */
    private String skillGroupIds;

    /**
     * 技能组名字
     */
    private String skillGroupNames;

    /**
     * 通话记录来源 0-呼叫中心 1-阿里云呼
     * @see com.xbongbong.saas.enums.CallCenterCallLogCallSourceEnum
     */
    private Integer callSource;

    /**
     * 创建时间
     */
    private Integer addTime;
    /**
     * 更新时间
     */
    private Integer updateTime;
    /**
     * 删除标记
     */
    private Integer del;
    /**
     * 用户名（坐席名）
     * 非持久层字段
     */
    private String userName;
    /**
     * 用于前端显示的时间
     * 非持久层字段
     */
    private String callTimeShow;
    /**
     * 用于前端显示"翻译按钮"
     * 非持久层字段
     */
    private Boolean isTranslated;

    public void copyOriginDetail(CallCenterCallLogEntity origin) {
        this.callTime = origin.getCallTime();
        this.duration = origin.getDuration();
        this.ringTime = origin.getRingTime();
        this.agentPhoneNum = origin.getAgentPhoneNum();
        this.result = origin.getResult();
        if (StringUtil.isNotEmpty(origin.getCallUuid())) {
            this.callUuid = origin.callUuid;
        }
        this.code = origin.getCode();
        this.note = origin.getNote();
        this.isSynced = true;
    }
}
